package forumTransform.forumTransformID;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;


public class WRun {

    public static void main(String[] args) throws Exception {

    	File f 					= new File ("Blogs.txt");
    	Path path = FileSystems.getDefault().getPath("C:\\Users\\Dan\\workspace\\forumTransformID\\src\\main\\java\\forumTransform\\forumTransformID", "Blogs.txt");
    	List<String> blogs = Files.readAllLines(path,java.nio.charset.Charset.defaultCharset());
    	List<WordpressJSON> allblogs = new ArrayList<WordpressJSON>();
    	
    	Utils.populateHtmlNumbers();

    	for (Iterator<String> it = blogs.iterator(); it.hasNext();) {
			String url = (String) it.next();
			WordpressJSON wBlog = Utils.createBlog(url,false);
			try {
				wBlog.populateBlog();
				wBlog.populateComments2();
				allblogs.add(wBlog);
				wBlog.process();
				wBlog.exportPolyCafe();
				ResultFileWriter outWriter		= new ResultFileWriter("participation-"+url, wBlog.exportCSV(), ".csv");
				outWriter.persist();
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println("found an exception ...");
				e.printStackTrace();
				System.out.println("trying to write what we crawled ...");
				try {
					wBlog.exportPolyCafe();
					ResultFileWriter outWriter		= new ResultFileWriter("participation-"+url, wBlog.exportCSV(), ".csv");
					outWriter.persist();
				} catch (Exception e2) {
					// TODO: handle exception
					System.out.println("found ANOTHER exception ...");
					e.printStackTrace();
					System.out.println("we can not write what we have ... continue");
				}
			}
			//break;
		}
    	System.out.println("End of reading blogs");
    	
    }

}
